# Copyright (c) Meta Platforms, Inc. and affiliates.

# @noautodeps

load("@fbcode_macros//build_defs:cpp_binary.bzl", "cpp_binary")
load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library")
load("@fbcode_macros//build_defs:cpp_unittest.bzl", "cpp_unittest")
load("@fbcode_macros//build_defs:fbcode_configured_alias.bzl", "fbcode_configured_alias")
load("@fbcode_macros//build_defs:thrift_library.bzl", "thrift_library")
load("@fbsource//tools/build_defs:default_platform_defs.bzl", "get_host_target_platform")
load("../../../defs.bzl", "zs_fuzzers")

oncall("data_compression")

thrift_library(
    name = "tulip_v2_data",
    languages = [
        "cpp2",
    ],
    thrift_cpp2_options = "reflection",
    thrift_srcs = ["tulip_v2_data.thrift"],
)

cpp_library(
    name = "tulip_v2_data_utils",
    headers = ["tulip_v2_data_utils.h"],
    deps = [
        "fbsource//xplat/tools/cxx:resources",
    ],
    exported_deps = [
        "..:tulip_v2",
        "../../../tests/datagen:datagen",
        "../../../tools:zstrong_cpp",
        "../../thrift/kernels/tests:thrift_kernel_test_utils",
        ":tulip_v2_data-cpp2-reflection",
        ":tulip_v2_data-cpp2-types",
        ":tulip_v2_data-cpp2-visitation",
        "//folly:range",
        "//folly:subprocess",
        "//folly/io:iobuf",
        "//thrift/lib/cpp2/protocol:protocol",
    ],
)

cpp_unittest(
    name = "test_tulip_v2",
    srcs = ["test_tulip_v2.cpp"],
    deps = [
        "..:tulip_v2",
        "../../..:zstronglib",
        ":tulip_v2_data_utils",
        "//folly:conv",
    ],
)

cpp_binary(
    name = "fuzz_tulip_v2_generator",
    srcs = ["fuzz_tulip_v2_generator.cpp"],
    deps = [
        ":tulip_v2_data_utils",
        "//folly:file_util",
        "//folly:string",
    ],
    external_deps = [
        ("openssl", None, "crypto"),
    ],
)

fbcode_configured_alias(
    name = "fuzz_tulip_v2_generator_host",
    actual = ":fuzz_tulip_v2_generator",
    platform = get_host_target_platform(),
)

zs_fuzzers(
    srcs = ["fuzz_tulip_v2.cpp"],
    ftest_names = [
        ("TulipV2Test", "FuzzRoundTrip"),
        ("TulipV2Test", "FuzzCompress"),
        ("TulipV2Test", "FuzzDecompress"),
    ],
    generator = ":fuzz_tulip_v2_generator_host",
    deps = [
        "..:tulip_v2",
        "../../../tests:fuzz_utils",
        "../../../tests:test_zstrong_fixtures",
        "fbsource//xplat/security/lionhead/utils/lib_ftest:lib",
        ":tulip_v2_data_utils",
    ],
)
